package xyz.cerberu.cet.anime.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import xyz.cerberu.cet.anime.domain.Anime;
import xyz.cerberu.cet.anime.service.AnimeServiceImpl;
import xyz.cerberu.cet.global.annotation.JsonFilter;
import xyz.cerberu.cet.global.domain.Result;
import xyz.cerberu.cet.global.utils.ResultUtils;

import java.util.List;

/**
 * @author β世界
 * @Name β世界
 * Created on 18:48
 * @Description 动漫相关的控制器
 */
@Controller
@RequestMapping("/anime")
public class AnimeControl {
    private final AnimeServiceImpl animeServiceImpl;

    @Autowired
    public AnimeControl(AnimeServiceImpl animeServiceImpl) {
        this.animeServiceImpl = animeServiceImpl;
    }

    /**
     * @author β世界 on 22:15 2020/4/9
     * @Description 获取某一天的更新信息
     * 前端传递一个时间，根据这个时间来查看那天的更新内容
     **/
    @JsonFilter(type = Anime.class,filter = "anime_url,introducation,quarter,update_Time,website,alias,year,week,isShow")
    @ResponseBody
    @GetMapping("/todayAnime")
    public Result<List<Anime>> todayAnimeUpdate(){
        return ResultUtils.genSuccessResult(animeServiceImpl.getNowAnimeUpdate());
    }

    /**
     * @author β世界 on 22:25 2020/4/9
     * @Description 获取一个动漫的详细信息
     **/
    @JsonFilter(type = Anime.class,filter = "anime_url,alias,year,week,quarter,isShow")
    @ResponseBody
    @RequestMapping("/details/{aniId}")
    public Result<Anime> details(@PathVariable(value = "aniId")String aniId) {
        Anime anime = animeServiceImpl.animeAbstract(aniId);
        return ResultUtils.genSuccessResult(anime);
    }
    
    /**
     * @author β世界 on 15:01 2021/3/15
     * 获得一个时间段的动漫
     * @param year: 年份
     * @param quarter: 季度
     * @return xyz.cerberu.cet.global.domain.Result<java.lang.Object>
     **/
    @JsonFilter(type = Anime.class,filter = "anime_url,introducation,quarter,update_Time,website,alias,year,week,isShow")
    @ResponseBody
    @RequestMapping(value = "/annual/{year}/{quarter}",method = RequestMethod.GET)
    public Result<Object> quarterAnime(@PathVariable("year") int year, @PathVariable("quarter") String quarter){
        // 获取一个季度的动漫
        List<Anime> anime = animeServiceImpl.sameYearAndQuarterAnime(year,quarter);
        if(anime != null){
            return ResultUtils.genSuccessResult(anime);
        }
        return ResultUtils.genFailResult("获取失败");
    }

}
